<?php

namespace Common\Model;
use think\Model;

class UserKuerpWarehouseOrdersModel extends UserKuerpWarehouseModel{

	//追加属性
    public $append = [
        'act_name',        //类型
        'product_name',
        'add_time_text',
	];

    /**
     * 操作
     * @param $value
     * @param $data
     * @return mixed
     */
    public function getActNameAttr($value, $data){
		$status_text = '';
		if($data['type']==1){
			$status_text = '入库';
		}else if($data['type']==2){
			$status_text = '出库';
		}
		return $status_text;
    }


    //搜索
    function _before_search(){
        $map = [];
        if(I('keyword')){
            $map['name'] = array('like','%'.I('keyword').'%');
        }
        $start_time = I('start_time');
        $end_time = I('end_time');
        if(!empty($start_time)||!empty($end_time)){
            if(empty($start_time)){
                $start_time = date('Y-m-d H:i:s',time());
            }
            if(empty($end_time)){
                $end_time =  date('Y-m-d H:i:s',time());
            }
            $start_time = strtotime($start_time);
            $end_time = strtotime($end_time);
            $map['add_time'] = array('between',[$start_time,$end_time]);
        }
        $map['is_delete'] = 0;
        return $map;
    }

}